package com.sav.common.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sav.common.catalog.Cart;
import com.sav.common.containers.ContentContainer;
import com.sav.common.localCatalog.Catalog;
import com.sav.common.localCatalog.LocalCategory;


@Controller
public class CartController {

	@RequestMapping(value = "/cart", method = RequestMethod.GET) 
    public String cartMethod(
    		ModelMap model,
    		HttpSession httpSession) throws Exception {
		Cart cart = (Cart) httpSession.getAttribute("cart");
		if (cart == null) {
			cart = new Cart();
			httpSession.setAttribute("cart", cart);
		}
		
		
        return "/cart"; 
    }
	
	@RequestMapping(value = "/addToCart", method = RequestMethod.POST)
    public @ResponseBody void addToCart(@RequestParam(value="id", required=true) Integer id,
           Model model,
           HttpSession httpSession)  throws Exception{
    	
		Cart cart = (Cart) httpSession.getAttribute("cart");
		if (cart == null) {
			cart = new Cart();
			httpSession.setAttribute("cart", cart);
		}

	}
}
